import os

ACCOUNT_FILE = 'account.txt'

def init_account():
    """
    :return:None
    """
    if not os.path.exists(ACCOUNT_FILE):
        with open("account.txt",mode = "w",encoding="utf-8") as f:
            f.write('123456 11111 1000\n')
            f.write('654321 22222 3000\n')

def add_acc(user,pwd):
    with open("account.txt", mode="a", encoding="utf-8") as f:
        f.write(f"{user} {pwd} 0\n")

def read_account():
    """
    读取账户
    :return:accounts
    """
    accounts={}
    with open("account.txt",mode="r",encoding="utf-8") as f:
        for i in f:
            card_num,pwd,cash = i.strip().split()
            accounts[card_num] = {"pwd":pwd,"cash":float(cash)}

        return accounts

def write_account(account):
    """
    向文件写数据
    :param account:
    :return:
    """
    with open("account.txt",mode="w",encoding="utf-8") as f:
        for i,j in account.items():
            f.write(f"{i} {j['pwd']} {j['cash']}\n")